import { createApp } from 'vue'
import App from './App.vue'

import "echarts";
import ECharts from 'vue-echarts'
// import { use } from "echarts/core";

// import {
//     CanvasRenderer
//   } from 'echarts/renderers'
//   import {
//     GridComponent,
//     TooltipComponent
//   } from 'echarts/components'

//   use([
//     CanvasRenderer,
//     GridComponent
//   ]);

import axios from 'axios'

import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';

import './assets/css/style.scss'

import router from './router'
import store from './store'
import components from './components';

//import './mock'

axios.interceptors.request.use(function (config) {
    if(store.state.login.token) {
        config.headers.authorization = 'Token ' + store.state.login.token
    }
    return config;
});

axios.interceptors.response.use(function (response) {
    if(response.data) {
        if(!response.data.hasOwnProperty('success')) {
            response.data.success = response.data.code == 20000
        }
    }

    return response
}, function(e) {
    if(e.response.status == 401) {
        router.push('/login')
    }
})

const app = createApp(App)

//全局注册组件
for(let key in components) {
    app.component('X' + key, components[key])
}

app.component('v-chart', ECharts)

app.use(Antd);
app.use(router)
app.use(store)

app.mount('#app')
